package com.zhuoshi.controller;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.ReceptionQuery;
import com.zhuoshi.bean.WdHtCustomer;
import com.zhuoshi.bean.WdReceptionRecord;
import com.zhuoshi.service.WdHtCustomerService;
import com.zhuoshi.service.WdReceptionRecordService;

@Controller
@RequestMapping("/reception") // 鍛藉悕绌洪棿
public class WdReceptionRecordController {
	@Autowired
	private WdReceptionRecordService service;
	@Autowired
	private WdHtCustomerService customerService;

	/**
	 *  鏌ヨ鍏ㄩ儴锛屾湁鏉′欢鏌ヨ
	 * @param bean
	 * @param model
	 * @return
	 */
	@RequestMapping("/WdReceptionList.do")
	public String list(ReceptionQuery bean, Model model) {
		List<WdReceptionRecord> list = service.getlist(bean);
		model.addAttribute("WdReceptionList", list);
		return "WdReceptionList";
	}

	/**
	 * 娣诲姞
	 * @return
	 */
	@RequestMapping("/WdReceptionToAdd.do")
	public String toadd(WdHtCustomer bean, Model model) {
		List<WdHtCustomer> list = customerService.getlist(null);
		model.addAttribute("WdCustomerList", list);
		return "WdReceptionAdd";

	}

	/**
	 * 鍔ㄦ�佹坊鍔�
	 * @param record
	 * @return
	 */
	@RequestMapping("/WdReceptionAdd.do")
	public String add(WdReceptionRecord record) {
		String string = UUID.randomUUID().toString();
		record.setReceptionRecordId(string);
		service.insertSelective(record);
		return "redirect:WdReceptionList.do";

	}

	/**
	 * 鍒犻櫎
	 * @param receptionRecordId
	 * @return
	 */
	@RequestMapping("/WdReceptionDelete.do")
	public String delete(String receptionRecordId) {
		service.deleteByPrimaryKey(receptionRecordId);
		return "redirect:WdReceptionList.do";
	}
	/**
	 * 淇敼锛屾煡璇㈡樉绀轰簬淇敼
	 * @param receptionRecordId
	 * @param model
	 * @return
	 */
	@RequestMapping("/WdReceptionToUpdate.do")
	public String toupdate(String customerId,Model model){
		List<WdHtCustomer> list = customerService.getlist(null);
		model.addAttribute("WdCustomerList", list);
		System.out.println("杈撳嚭"+customerId);
		WdReceptionRecord reception = service.selectByPrimaryKey(customerId);
		model.addAttribute("reception", reception);
		return "WdReceptionUpdate";
	}
	
	/**
	 * 鍔ㄦ�佷慨鏀�
	 * @param reception
	 * @return
	 */
	@RequestMapping("/WdReceptionUpdate.do")
	public String update(WdReceptionRecord reception){
		service.updateByPrimaryKeySelective(reception);
		return "redirect:WdReceptionList.do";
		
	}

}
